package com.hhkj.study.admin.resource.factory;

import com.google.common.collect.Maps;
import com.hhkj.study.admin.resource.service.extend.ResourceCourseBaseExtendService;
import com.ruoyi.common.utils.spring.SpringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Map;

/**
 * @Author luowu
 * @Date 2024/10/15 涵 10:08:22
 */
@Component
public class CourseResourceFactory {

    /**
     * 资源类型与资源service的映射
     */
    private static Map<String, ResourceCourseBaseExtendService> resourceCourseServiceConcurrentMap = Maps.newConcurrentMap();

    @PostConstruct
    public void init() {
        Map<String, ResourceCourseBaseExtendService> resourceCourseServiceMap = SpringUtils.listBeanOfType(ResourceCourseBaseExtendService.class);
        resourceCourseServiceMap.forEach((k, v) -> resourceCourseServiceConcurrentMap.put(v.getCourseResourceTypeEnum().getCode(), v));
    }

    /**
     * 根据资源类型获取对应的service
     * @param resourceType
     * @return
     */
    public static ResourceCourseBaseExtendService getResourceServiceByType(String resourceType) {
        return resourceCourseServiceConcurrentMap.get(resourceType);
    }
}
